package com.lxx.train.business.controller.admin;

import com.lxx.train.common.resp.CommonResp;
import com.lxx.train.common.resp.PageResp;
import com.lxx.train.business.req.TrainStationQueryReq;
import com.lxx.train.business.req.TrainStationSaveReq;
import com.lxx.train.business.resp.TrainStationQueryResp;
import com.lxx.train.business.service.TrainStationService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/train-station")
public class TrainStationAdminController {

    @Autowired
    private TrainStationService trainStationService;

    // 新增 / 更新
    // 判断前端有无传id，没有则是新增，否则是更新
    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody TrainStationSaveReq req) {
        trainStationService.save(req);
        return CommonResp.ok();
    }

    // 查询列表
    @GetMapping("/query-list")
    public CommonResp<PageResp<TrainStationQueryResp>> queryList(@Valid TrainStationQueryReq req) {
        PageResp<TrainStationQueryResp> pageResp = trainStationService.queryList(req);
        return CommonResp.ok(pageResp);
    }

    // 删除
    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable Long id) {
        trainStationService.delete(id);
        return CommonResp.ok();
    }

}
